package com.tyk.bookstore.back.product.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tyk.bookstore.back.common.core.util.FileUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;

@Schema(name = "DisplayImage", description = "书籍展示图片")
@TableName("display_image")
@Data
@NoArgsConstructor
public class DisplayImageDo implements Serializable {
    @Serial
    private static final long serialVersionUID = 1;
    @Schema(description = "ID")
    @TableId("id")
    private Long id;
    @Schema(description = "书籍ID")
    @TableField("book_id")
    private Long bookId;
    @Schema(description = "路径")
    @TableField("path")
    private String path;

    public DisplayImageDo(Long bookId, String path) {
        this.bookId = bookId;
        this.path = FileUtil.relativePath(path);
    }

    public DisplayImageDo setPath(String path) {
        this.path = FileUtil.relativePath(path);
        return this;
    }
}
